<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加商品</title>
    <link rel="stylesheet" href="{{static_url('layui/css/layui.css')}}">
    <link rel="stylesheet" href="{{static_url('layui/css/layui.mobile.css')}}">
    <link rel="stylesheet" type="text/css" href="{{static_url('webupload/webuploader.css')}}">
    <link rel="stylesheet" href="{{static_url('webupload/demo.css')}}">
    <link rel="stylesheet" type="text/css" href="{{static_url('webupload/bootstrap.min.css')}}">
    <link rel="stylesheet" type="text/css" href="{{static_url('webupload/bootstrap-theme.min.css')}}">
    <link rel="stylesheet" type="text/css" href="{{static_url('webupload/font-awesome.min.css')}}">
    <link rel="stylesheet" type="text/css" href="{{static_url('webupload/syntax.css')}}">
    <link rel="stylesheet" type="text/css" href="{{static_url('webupload/style.css')}}">
</head>
<style>
    .layui-form-label {
        display: inline-block;
        width: 110px;
        text-align: justify;
    }
</style>
<body>
<div class="good-fox" style="margin: 20px">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">商&nbsp;&nbsp;品&nbsp;&nbsp;名</label>
            <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" placeholder="请输入名称" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">价&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;格</label>
            <div class="layui-input-inline">
                <input type="number" name="price" placeholder="" autocomplete="off" class="layui-input" step="0.00">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;型</label>
            <div class="layui-input-inline">
                <select name="city" lay-verify="">
                    {% for classify in classifies %}
                    {% if classify.id == 1 %}
                    <option value="{{classify.id}}">请选择商品类型</option>
                    {% else %}
                    <option value="{{classify.id}}">{{classify.name}}</option>
                    {% end %}
                    {% end %}
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">商品介绍</label>
            <div class="layui-input-block">
                <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">服&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;务</label>
            <div class="layui-input-block">
                <input type="checkbox" name="like[tb]" title="退货补邮费">
                <input type="checkbox" name="like[7t]" title="7天无理由退货">
                <input type="checkbox" name="like[by]" title="全国包邮">
                <input type="checkbox" name="like[72fh]" title="72小时内发货">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">立即上架</label>
            <div class="layui-input-block">
                <input type="checkbox" name="switch" lay-skin="switch">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">下一步</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <!--dom结构部分-->
    <div id="uploader" class="wu-example" style="display: none">
        <div class="queueList">
            <div id="dndArea" class="placeholder">
<!--                <div id="filePicker"></div>-->
                <p>将照片拖到这里，单次最多可选300张</p>
            </div>
        </div>
        <div class="statusBar" style="display:none;">
            <div class="progress">
                <span class="text">0%</span>
                <span class="percentage"></span>
            </div>
            <div class="info"></div>
            <div class="btns">
                <div id="filePicker2"></div>
                <div class="uploadBtn">开始上传</div>
            </div>
        </div>
    </div>
</div>

<script src="{{static_url('js/jquery-3.2.1.min.js')}}"></script>
<script src="{{static_url('layui/layui.all.js')}}"></script>
<script type="text/javascript" src="{{static_url('webupload/webuploader.js')}}"></script>
<script src="{{static_url('webupload/demo.js')}}"></script>
<script type="text/javascript" src="{{static_url('webupload/bootstrap.min.js')}}"></script>
<script type="text/javascript" src="{{static_url('webupload/global.js')}}"></script>
<script type="text/javascript">
    var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
    document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F67c4841095cbee8275705e1f6224a3c7' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
    layui.use('form', function () {
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function (data) {
            $('.layui-form').css('display', 'none');
            $('#uploader').css('display', 'block');
            let status = false;
            if (data.field.switch == 'on') {
                status = true;
            }
            let serves = '';
            let data_str = JSON.stringify(data.field);
            if (data_str.indexOf('tb') != -1) {
                serves += 1
            }
            if (data_str.indexOf('7t') != -1) {
                serves += 2
            }
            if (data_str.indexOf('by') != -1) {
                serves += 3
            }
            if (data_str.indexOf('72fh') != -1) {
                serves += 4
            }
            $.ajax({
                url: '/admin_add_shop',
                method: 'post',
                data: {
                    'name': data.field.title,
                    'price': data.field.price,
                    'desc': data.field.desc,
                    'serves': serves,
                    'classify': data.field.city,
                    'status': status,
                },
                success: function (data) {
                    console.log(data);
                    if (data.status) {
                        layer.msg('请上传图片');
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>